package com.example.broadcast.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.NetworkInfo;
import android.util.Log;

import com.example.broadcast.Util.NetworkUtil;

public class NetChangeReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        if(intent!=null)
        {
            NetworkInfo networkInfo=intent.getParcelableExtra("networkInfo");
            String text=String.format("收到一个网络变更广播，网络大类为%s,"+
                    "网络小类为s,网络制式为%s,网络状态为：%s",
                    networkInfo.getTypeName(),
                    networkInfo.getSubtypeName(),
                    NetworkUtil.getNetworkClass(networkInfo.getSubtype()),
                    networkInfo.getState().toString());
            Log.d("tang",text);
        }
    }
}
